from sqlalchemy import (
    Column,
    Index,
    Integer,
    Text,
    Unicode,
    ForeignKey,
    Table,
    Float,
    DateTime
)
from sqlalchemy.orm import relationship
from .meta import Base


cart_item=Table('cart_item',Base.metadata,
                Column('cart_id',Integer,ForeignKey('carts.id'),primary_key=True),
                Column('item_id',Integer,ForeignKey('items.id'),primary_key=True)
               )

class Cart(Base):
    __tablename__='carts'
    id = Column(Integer, primary_key=True)
    user_id=Column(Integer,ForeignKey('users.id'),nullable=True)
    user=relationship("User",backref='cart')
    items=relationship('Item',secondary=cart_item)
    item_num=Column(Integer,nullable=False,default=1)